package com.hpin.mlxteacher.my;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hpin.mlxteacher.R;
import com.hpin.mlxteacher.base.BaseActivity;
import com.hpin.mlxteacher.utils.CommonUtils;
//import com.umeng.analytics.MobclickAgent;

/**
 * 修改个人姓名页面
 * Created by Aaron on 15/7/31.
 */
public class ChangeNameActivity extends BaseActivity {

    private static final int CHANGE_NAME_CODE = 10021;

    private EditText et_name;
    private String name;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_chage_name);
        name = getIntent().getStringExtra("name");
        initWidget();

    }

    private void initWidget() {

        ImageView tv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);
        TextView tv_right = (TextView) findViewById(R.id.tv_right);

        tv_title.setText(getResources().getString(R.string.change_name));
        tv_right.setText(getResources().getString(R.string.done));

        tv_left.setOnClickListener(this);
        tv_right.setOnClickListener(this);

        et_name = (EditText) findViewById(R.id.et_name);
        et_name.setText(name);
        //设置光标在内容后面
        et_name.setSelection(et_name.getText().toString().length());
    }

    @Override
    public void widgetClick(View v) {
        switch (v.getId()) {
            case R.id.iv_left:
                finish();
                break;
            case R.id.tv_right:

                String name = et_name.getText().toString().trim();

                if (CommonUtils.isNull(name)) {

                    showToast("姓名不能为空");
                    return;
                }
                //姓名传给上一个页面
                String modifyName = et_name.getText().toString().trim();
                Intent data = new Intent();
                data.putExtra("modifyname", modifyName);
                setResult(CHANGE_NAME_CODE, data);
                finish();
                break;

        }
    }

//    public void onResume() {
//        super.onResume();
//        MobclickAgent.onResume(this);       //统计时长
//    }
//
//    public void onPause() {
//        super.onPause();
//        MobclickAgent.onPause(this);
//    }
}
